//
//  HYDetailViewController.m
//  MusicMV
//
//  Created by Eternity on 16/3/22.
//  Copyright © 2016年 Eternity. All rights reserved.
//

#import "HYDetailViewController.h"

@interface HYDetailViewController ()<UITableViewDelegate , UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic , strong) UIImageView *backGroundImage;
@property (nonatomic , strong) UIVisualEffectView *visualEfView;
@property (nonatomic , strong) UIBarButtonItem *buttonLeft;
@property (nonatomic , strong) HYDetailModel *model;
@property (nonatomic , strong) UILabel *labelLift;
@property (nonatomic , strong) UILabel *labelRight;
@property (nonatomic , strong) NSMutableArray *arrDetailModel;
@property (nonatomic , assign) NSInteger page;

@end



@implementation HYDetailViewController

- (void)dealloc
{
    _tableView.delegate = nil;
    _tableView.dataSource = nil;
    
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _page = 20;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    self.navigationItem.title = self.titleNav;
    self.view.backgroundColor= [UIColor blackColor];
    self.backGroundImage = [[UIImageView alloc] init];
    self.backGroundImage.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    [_backGroundImage sd_setImageWithURL:[NSURL URLWithString:self.headerImage]];
    _backGroundImage.userInteractionEnabled = YES;
    self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _visualEfView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _visualEfView.alpha = 1;
    _visualEfView.userInteractionEnabled = YES;
    UIView *viewBack = [[UIView alloc] initWithFrame:_backGroundImage.frame];
    viewBack.backgroundColor = [UIColor blackColor];
    viewBack.alpha = 0.8;
    [_backGroundImage addSubview:viewBack];
    [_backGroundImage addSubview:_visualEfView];
    
    [self.view addSubview:_backGroundImage];
    
    
    
    self.buttonLeft = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"goBack"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]style:(UIBarButtonItemStylePlain) target:self action:@selector(buttonLeft:)];
    
    self.navigationItem.leftBarButtonItem = _buttonLeft;

    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    _tableView.contentInset = UIEdgeInsetsMake(150 * ht, 0, 0, 0);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.rowHeight = 100 * ht;
    [_visualEfView addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 50 * wt , - 150 * ht + 10 * ht, 100 * wt, 100 * ht)];
    [image sd_setImageWithURL:[NSURL URLWithString:_headerImage]];
    [_tableView addSubview:image];
    image.layer.cornerRadius = 50;
    image.backgroundColor = [UIColor clearColor];
    UIImageView *imageleft = [[UIImageView alloc] initWithFrame:CGRectMake(50 * wt, - 150 * ht +  110 * ht, 16 * wt, 16 * ht)];
    imageleft.image = [UIImage imageNamed:@"mmmvv"];
    imageleft.backgroundColor = [UIColor clearColor];
    [_tableView addSubview:imageleft];
    self.labelLift = [[UILabel alloc] initWithFrame:CGRectMake(70 * wt,- 150 * ht + 110 * ht, 100 * wt, 20 * ht)];
    _labelLift.backgroundColor = [UIColor clearColor];
    _labelLift.textColor = [UIColor whiteColor];
    [_tableView addSubview:_labelLift];
    _labelLift.font = [UIFont systemFontOfSize:13];
    UIImageView *imageright = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 50 * wt,- 150 * ht +  110 * ht, 16 * wt, 16 * ht)];
    imageright.image = [UIImage imageNamed:@"likeLove"];
    imageright.backgroundColor = [UIColor clearColor];
    [_tableView addSubview:imageright];
    self.labelRight = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 70 * wt ,- 150 * ht +  110 * ht, 150 * wt, 20 *ht)];
    _labelRight.backgroundColor = [UIColor clearColor];
    _labelRight.textColor = [UIColor whiteColor];
    [_tableView addSubview:_labelRight];
    [self DataHandle];
    _labelRight.font = [UIFont systemFontOfSize:13];

    [_tableView registerClass:[HYSameTableViewCell class] forCellReuseIdentifier:@"HYSameTableViewCell"];
    self.tableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        _page += 20;
        
        [self DataHandleLoad];
        
        
    }];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _arrDetailModel.count;


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HYSameTableViewCell *sameCell = [tableView dequeueReusableCellWithIdentifier:@"HYSameTableViewCell" forIndexPath:indexPath];
    sameCell.model = _arrDetailModel[indexPath.row];
    sameCell.backgroundColor = [UIColor clearColor];
    sameCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return sameCell;


}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    HYVideoPlayerViewController * hy = [[HYVideoPlayerViewController alloc]init];
    HYVideoPlayerModel * model = _arrDetailModel[indexPath.row];
    
    hy.thumbImage = model.thumbnailPic;
    hy.titleNav = model.title;
    hy.urlID = model.ID;
    hy.shdUrl = model.hdUrl;
    hy.totoaView = model.totalViews;
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController pushViewController:hy animated:YES];



}


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    cell.layer.transform = CATransform3DMakeRotation(1, 1, 0, 0);
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeRotation(0, 0, 0, 0);
    }];


}


- (void)DataHandleLoad {
    
    NSDictionary *dic = @{@"Device-Id":@"cb38b93ffda5c09483eaf6cda8874345",@"App-Id":@"10101027",@"Device-V":@"aVBob25lIE9TXzkuMV82NDAqMTEzNl8xMDAwMDEwMDBfaVBob25lIDU="};

    
    
    [XRAFNetworkTool GETUrl:[NSString stringWithFormat:@"http://mapi.yinyuetai.com/video/list_by_artist.json?D-A=0&artistId=%@&offset=%ld&size=20",_AID,_page] body:nil headFile:dic response:XRJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *arr = responseObject[@"videos"];
        NSMutableArray * arrM = [HYVideoPlayerModel modelWithArray:arr];
        for (HYVideoPlayerModel *model in arrM) {
            [self.arrDetailModel addObject:model];
        }
        [_tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
    
}




- (void)DataHandle {
    NSDictionary *dic = @{@"App-Id":@"10101027",@"Device-Id":@"cb38b93ffda5c09483eaf6cda8874345",@"Device-V":@"aVBob25lIE9TXzkuMV82NDAqMTEzNl8xMDAwMDEwMDBfaVBob25lIDU="};
    
  [XRAFNetworkTool GETUrl:[NSString stringWithFormat:@"http://mapi.yinyuetai.com/artist/show.json?D-A=0&artistId=%@&size=20",self.AID]body:nil headFile:dic response:XRJSON success:^(NSURLSessionDataTask *task, id responseObject) {
      
      self.model = [HYDetailModel modelWithDic:responseObject[@"artist"]];
      _labelLift.text =[NSString stringWithFormat:@"%@首MV",_model.videoCount];
      _labelRight.text = [NSString stringWithFormat:@"%@人喜欢",_model.fanCount];
      NSArray *arr = responseObject[@"videos"];
      self.arrDetailModel = [HYVideoPlayerModel modelWithArray:arr];
      [_tableView reloadData];
  } failure:^(NSURLSessionDataTask *task, NSError *error) {
      
  }];
   


}



- (void)buttonLeft:(UIBarButtonItem *)button {
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = RGBA(38,38, 38, 1);
    
    self.navigationController.navigationBar.alpha = 1;
    
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
